package com.leo;

import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ChoiceDialog;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;

/**
 * @ClassName ChoiceDialogDemo
 * @Description
 * @Author wangss
 * @date 2020.06.13 18:32
 * @Version 1.0
 */
public class ChoiceDialogDemo extends Application {
    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) throws Exception {
        AnchorPane anchorPane = new AnchorPane();
        anchorPane.setStyle("-fx-background-color: #fff2f2");

        Button button = new Button("弹框");

        AnchorPane.setTopAnchor(button, 20d);
        AnchorPane.setLeftAnchor(button, 20d);
        anchorPane.getChildren().addAll(button);
        Scene scene = new Scene(anchorPane);
        primaryStage.setScene(scene);
        primaryStage.setWidth(800d);
        primaryStage.setHeight(800d);
        primaryStage.setTitle("Dialog");
        primaryStage.setResizable(false);
        primaryStage.show();

        button.setOnAction(event -> {
            ObservableList<String> list = FXCollections.observableArrayList();
            list.add("a");
            list.add("b");
            list.add("c");
            ChoiceDialog<String> choiceDialog = new ChoiceDialog<>("data", list);

            choiceDialog.show();

            choiceDialog.selectedItemProperty().addListener((observable, oldValue, newValue) -> {
                System.out.println(newValue);
            });
        });
    }
}
